import request from '@/utils/request'

// 1.订单确认
// mode 决定传递参数的方式
// mode: cart => obj {cartIds,remark}
// mode: buyNow => obj {goodsId,goodsNum,goodsSkuId,remark}
export const checkOrder = (mode, obj) => {
  return request.get('/checkout/order', {
    params: {
      mode,
      delivery: 10, // 快递方式
      couponId: 0, // 优惠券ID
      isUsePoints: 0, // 使用积分
      ...obj // 传递过来的参数对象，动态展开
    }
  })
}

// 2.提交订单
// mode: cart => obj {cartIds,remark}
// mode: buyNow => obj {goodsId,goodsNum,goodsSkuId,remark}
export const submitOrder = (mode, obj) => {
  return request.post('/checkout/submit', {
    mode,
    delivery: 10, // 快递方式
    couponId: 0, // 优惠券ID
    isUsePoints: 0, // 使用积分
    payType: 10, // 余额支付
    ...obj
  })
}

// 3.获取订单列表
export const getMyOrderList = (dataType, page) => {
  return request.get('/order/list', {
    params: {
      dataType,
      page
    }
  })
}
